package com.zzxz.practicaltrainingsys.mapper;

import com.zzxz.practicaltrainingsys.entity.Grade;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GradeMapper {
    // 查询所有年级
    @Select("select * from grade")
    List<Grade> getGrade();

    // 根据ID查找
    @Select("select * from grade where grade_id = #{grade_id}")
    Grade getGradeById(@Param("grade_id") Integer grade_id);

    // 新增
    @Insert("insert into grade (grade_name, major_id) values (#{grade_name}, #{major_id})")
    @Options(useGeneratedKeys = true, keyProperty = "grade_id")
    int addGrade(Grade grade);

    //更新
    @Update("update grade set grade_id=#{grade_id},grade_name=#{grade_name} where grade_id=#{grade_id}")
    int updateGrade(Grade grade);

    //根据专业编号查找年级名称
    @Select("select * from grade where major_id = #{major_id}")
    List<Grade> getGradeByMajorId(@Param("major_id") Integer major_id);
}